/*
 * @Date: 2024-10-22 10:58:20
 * @Author: LiSong
 * @LastEditors: LiSong
 * @LastEditTime: 2024-12-18 14:36:26
 * @Description: 函数式调用弹窗类
 */

import { render, createVNode } from 'vue';

/**
 * 调用组件类
 */
export class CallComp {
  constructor(app) {
    this.nodeApp = app
  }
  open(comp, props) {
    if (!this.nodeApp) {
      console.log('未找到APP对象！')
      return
    }
    const container = document.createElement('div')
    // 设置样式
    container.className = `call-comp-popper ${ props.className || props.class || '' }`

    // 销毁容器
    const destroy = () => {
      render(null, container)
      document.body.removeChild(container)
    }

    const vmNode = createVNode(comp, {
      ...props,
      visible: true,
      onDestory: destroy
    })

    // 继承上下文
    vmNode.appContext = this.nodeApp._context
    render(vmNode, container)
    document.body.appendChild(container)
  }
}

export default CallComp
